local CommonOHOH = _G.CommonOHOH;
local EventList = _G.ServerOHOH.load.EventList();

local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent());
local CallBackManager = CommonOHOH.load.CallBackManager();


-- 服务器广播给其它玩家
function M.new(self, ...)
	return M(self, ...);
end;


function M.ctor(self,...)
    M.super.ctor(self,...)
   
    self.player=self.parent.player
    self.character=self.parent.character

    self.bulletId=self.parent:GetBulletId()
    self.bulletSpeed=self.parent:GetBulletSpeed()
    self.isPenetrate=self.parent:IsPenetrate()
    self.Lenght=self.parent:GetBulleFlyLenght()

    -- -- 收到同步给客户端操作
    -- self.parent.Syn2ClientEvent:Connect(function(...)
    --         self:SendBullet(...)
    --  end)

     CallBackManager:AddRbxConnect(self,self.parent.Syn2ClientEvent, function(obj,...)
        self:SendBullet(...)
    end);


end;


function M.dtor(self)
    -- print("------武器被销毁-----Syn2Client--------->")

	M.super.dtor(self);
end;

-- 给定一个玩家，判断是否广播
function M.isSyn(self,player)
    --目前是除了自己，所有玩家都发送消息
    if  player==self.player then
         return false
    end
    return true
end


--根据guid找到参战者(一切有血量或者攻击力的对象)
function M.FindCombatantEvent(self,guid)
     local list= self.player.FindCombatantEvent:Action(guid)
     for k,v in pairs(list) do
        return v
     end
end


--重写发射类， 发射子弹信息，同步给其它玩家
function M.SendBullet(self,arg)
    local userId=self.player:GetUserId()
    for player,v in pairs(_G.server:GetPlayerList()) do
        if player and  self:isSyn(player) then
            player:Fire(EventList.Other_Player_Shoot,userId,self.bulletId,self.bulletSpeed,arg.pos)
        end
    end
    local obj=nil
    if  arg.guid then
        obj=self:FindCombatantEvent(arg.guid)
    end
    
    if obj then
        local arrive=_G.CommonOHOH.load.Connect().new()
        self.parent:PushDamge(obj,self.player,arrive)
        self:AddProcess(function()
            self:Wait(arg.flyTime)
            arrive:Action()
            arrive:dtor()
        end)
    else

    end
 end
return M;